﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp5_StackPanel
{
    /// <summary>
    /// Window3.xaml 的交互逻辑
    /// </summary>
    public partial class Window3 : Window
    {
        public Window3()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            Grid gmain = new Grid();
            TopPanel.Children.Add(gmain);

            ColumnDefinition coldef = new ColumnDefinition();
            coldef.Width = new GridLength(200);
            gmain.ColumnDefinitions.Add(coldef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100);
            gmain.ColumnDefinitions.Add(coldef);

            PropertyInfo[] pilist = typeof(Colors).GetProperties();
            int i = 0;
            foreach(PropertyInfo pi in typeof(Colors).GetProperties())
            {
                RowDefinition rowdef = new RowDefinition();
                rowdef.Height = new GridLength(100);
                gmain.RowDefinitions.Add(rowdef);

                Color mColor;
                mColor = (Color)pi.GetValue(null, null);
                Label lb = new Label();
                lb.Content = pi.Name;
                lb.HorizontalAlignment = HorizontalAlignment.Center;

                gmain.Children.Add(lb);
                Grid.SetRow(lb, i);
                Grid.SetColumn(lb, 0);

                Rectangle rect = new Rectangle();
                rect.Fill = new SolidColorBrush(mColor);
                rect.Width = 100;
                rect.Height = 20;

                gmain.Children.Add(rect);
                Grid.SetRow(rect, i);
                Grid.SetColumn(rect, 1);

                i++;
            }

            GridSplitter split = new GridSplitter();
            split.HorizontalAlignment = HorizontalAlignment.Center;
            split.Width = 6;

            gmain.Children.Add(split);
            Grid.SetRow(split, 0);
            Grid.SetColumn(split, 1);
        }
    }
}
